package h0825;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;

/**
  * @description 有效的括号
  * @author 不知名帅哥
  * @date 2024/8/25 21:35
  * @version 1.0
*/
public class ValidBracket {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String s = sc.nextLine();
        boolean v=isValid(s);
        System.out.println(v);
    }

    static HashMap<Character,Character> map=new HashMap<>();
    static {
        map.put('(',')');
        map.put('[',']');
        map.put('{','}');
    }
    private static boolean isValid(String s) {
        LinkedList<Character> stack=new LinkedList<>();
        //依次入栈
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c=='('||c=='['||c=='{'){
                stack.offerLast(c);
            }
            if (c==')'||c=='}'||c==']'){
                if (stack.isEmpty()){
                    //如果第一个是右括号直接false
                    return false;
                }else if (map.get(stack.peekLast())==c){
                    stack.removeLast();
                }else {
                    return false;
                }
            }
        }
        return stack.isEmpty();
    }

}
